<?php
$this->LoadHelper('ApiHelper');
$ApiHelper = new ApiHelper();

$this->LoadHelper('OrderHelper');
$OrderHelper = new OrderHelper();

$this->LoadHelper('MemberHelper');
$MemberHelper = new MemberHelper();

$check = $ApiHelper->tokenCheck($this->Param);
if(!$check['success']) ErrorMsg::ApiMsg($check['msg'], $check['code']);

switch($this->Param['option']){
    case 'save':
        $oid = empty($this->Param['oid']) ? ErrorMsg::ApiMsg('参数错误') : $this->Param['oid'];
        $order_check = $OrderHelper->checkOrderper($oid, $this->Param['uid']);
        if(!$order_check['success'])                ErrorMsg::ApiMsg ('无权操作', 20000);
        $fares = empty($this->Param['fares']) ? ErrorMsg::ApiMsg('请上传车资附件') : $this->Param['fares'];
        $getcar = empty($this->Param['getcar']) ? ErrorMsg::ApiMsg('请上传提车影像') : $this->Param['getcar'];
        $order_info = $OrderHelper->orderRow($oid);
        $member_info = $MemberHelper->getMemberRow($this->Param['uid']);
        $ApiHelper->logSave('order_afteratt', $this->Param);
        if(!empty($fares)) foreach($fares as $k => $v){
            $data[] = array(
                'af_oid' => $oid,
                'af_number' => $order_info['o_number'],
                'af_uid' => $this->Param['uid'],
                'af_uname' => $member_info['u_realname'],
                'af_file' => $v,
                'af_class' => '车资',
                'af_dateline' => NOW_TIME
            );
        }
        if(!empty($getcar)) foreach($getcar as $k => $v){
            $data[] = array(
                'af_oid' => $oid,
                'af_number' => $order_info['o_number'],
                'af_uid' => $this->Param['uid'],
                'af_uname' => $member_info['u_realname'],
                'af_file' => $v,
                'af_class' => '提车影像',
                'af_dateline' => NOW_TIME
            );
        }
        $OrderHelper->afattachSave(array('af_status' => 'del'), array('`af_oid` = ?' => $oid));
        foreach($data as $k => $v){
            $id = $OrderHelper->afattachSave($v);
        }
        if($id){
            $ApiHelper->logSave('order_afteratt', $this->Param);
            ErrorMsg::ApiMsg('保存成功', 0);
        }else{
            ErrorMsg::ApiMsg('保存失败');
        }
        break;
    default :
}